<?php

namespace app\admin\validate\hospital;

use think\Validate;

class HospitalDiscount extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'hospital_id'=>'require',
        'goods_id'=>'require',
        'money' => 'float|gt:0',
        'discount'=>'between:1,100',
    ];
    /**
     * 提示消息
     */
    protected $message = [
        'hospital_id.require' => '医院不能为空',
        'goods_id.require' => '项目不能为空',
        'money.gt' => '金额必须大于0',
        'money.require' => '金额不能为空',
        'discount.between' => '折扣必须在1-100之间',
        'discount.require' => '折扣不能为空',
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => ['hospital_id','goods_id','money','discount'],
        'edit' => ['hospital_id','goods_id','money','discount'],
    ];

    public function __construct(array $rule = [], array $message = [], array $field = [])
    {
        parent::__construct($rule, $message, $field);
        $data = request()->post("row/a");

        if ($data['type'] == 10) {
            $this->rule['discount'] = 'require|between:1,100';
            unset($this->rule['money']);
        }else{
            $this->rule['money'] = 'require|float|gt:0';
            unset($this->rule['discount']);
        }
    }
    
}
